'use strict';

    angular.module('app')
        .controller('menuDetailsController', ['$scope', '$rootScope', '$state', '$timeout', 'toaster',
                                             function($scope, $rootScope, $state, $timeout, toaster) {
        var title = "";
        var defaultAva = $rootScope.defaultAvatar;
        $scope.myImage='';
        // $scope.myCroppedImage=$scope.myCroppedImage ;
        $scope.myCroppedImage = '';
        title="菜单详情";
        var id = $state.params.id;
        activate(id);
        //将所有的input，select标签弄成不可编辑
		$("input").attr("disabled",true);
		$("select").attr("disabled",true);
        $scope.title = $rootScope.title = title;
        $scope.loading = true;
        
        $scope.selUser = function(){
        	$scope.record.personId=$scope.record.person.split('_')[0];
        	$scope.record.cardNo=$scope.record.person.split('_')[1];
        }
        
        var handleFileSelect=function(evt) {
            var file=evt.currentTarget.files[0];
            if(!/image\/\w+/.test(file.type)){
                return false;
            }
            var reader = new FileReader();
            reader.onload = function (evt) {
                $scope.$apply(function($scope){
                    $scope.myImage=evt.target.result;
                });
            };
            reader.readAsDataURL(file);
        };
        angular.element(document.querySelector('#fileInput')).on('change',handleFileSelect);
        
        // 初始化页面
        function activate(id) {
	        $scope.loading = true;
        	$.ajax({
        		type: 'PUT',
	            dataType: 'json',
				contentType:'application/json;charset=UTF-8',
				url : '/menu/sysmenu/detail',
				data: angular.toJson({'id': id})
			}).then(function(result) {
		        $scope.loading = false;
				if (result.httpCode == 200) {
					$scope.record = result.data;
//					console.log(result);
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
        }
        
    }]);